/**
 * 
 */
package com.hyfrogx.common.utils;

import com.mchange.v2.util.PropertiesUtils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import java.util.Properties;

/**
 * 
 * @项目 hyplatform v2.0
 *
 * @日期: 2017-8-1 14:10:37
 * 
 * @负责人: Li9527
 */
public class ImUtils {

	// 云API密钥SecretId
	public static String sdkAppId;
	// 云API密钥StrSecKey
	public static String identifier;
	// 直播推流防盗链key
	public static String usersig;
	// C调用注册表位置
	public static String jnisigcheck;
	// 私钥文件的路径
	public static String priKeyFile;
	// 私钥文件的路径
	public static String pubKeyFile;
	// 头像路径
	public static String faceUrl;
	// 脏字库文件存放路径
	public static String senSitWordUrl;
	
	
	/**
	 * 加载系统配置文件
	 */
	public static void loadImPropertys() {
		Properties properties;
		properties = loadProperties("Im.properties");
		// 如果配置保留的是正式服务器配置
		if (null != properties) {
			Iterator<String> it = properties.stringPropertyNames().iterator();
			while (it.hasNext()) {
				String key = it.next();
				System.setProperty(key, properties.getProperty(key));
				String value = properties.getProperty(key).toString();
				System.out.println(
						"当前properties的key为:" + key + "——————/当前properties的value为：" + properties.getProperty(key));
				if (key.equals("sdkAppId")) {
					ImUtils.sdkAppId = value;
					continue;
				}
				if (key.equals("identifier")) {
					ImUtils.identifier = value;
					continue;
				}
				if (key.equals("usersig")) {
					ImUtils.usersig = value;
					continue;
				}
				if (key.equals("jnisigcheck")) {
					ImUtils.jnisigcheck = value;
					continue;
				}if (key.equals("priKeyFile")) {
					ImUtils.priKeyFile = value;
					continue;
				}if (key.equals("pubKeyFile")) {
					ImUtils.pubKeyFile = value;
					continue;
				}if (key.equals("faceUrl")) {
					ImUtils.faceUrl = value;
					continue;
				}if (key.equals("senSitWordUrl")) {
					ImUtils.senSitWordUrl = value;
					continue;
				}
			}
		}
	}

	/**
	 * 加载properties文件
	 * 
	 * @param resources
	 * @return
	 */
	private static Properties loadProperties(String resources) {
		System.out.println("loadProperties:" + resources);
		// 使用InputStream得到一个资源文件
		InputStream inputstream = PropertiesUtils.class.getClassLoader().getResourceAsStream(resources);
		// new 一个Properties
		Properties properties = new Properties();
		try {
			// 加载配置文件
			properties.load(inputstream);
			return properties;
		} catch (IOException e) {
			throw new RuntimeException(e);
		} finally {
			try {
				inputstream.close();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
	}
	
}
